//package com.shycloud.mido.homework.annotation;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.alibaba.fastjson.serializer.SerializerFeature;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.shycloud.mido.common.core.util.R;
//import lombok.SneakyThrows;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.BufferedReader;
//import java.io.IOException;
//
//@Component
//@Aspect
//public class LogRAspect {
//
//	@Pointcut("execution(public * com.shycloud.mido.homework.controller.*.*(..))")
//	public void webLog() {
//	}
//
//	@SneakyThrows
//	@AfterReturning(returning = "r", pointcut = "webLog()")
//	public void doAfterReturning(R r) {
//
//		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//
//		HttpServletRequest request = attributes.getRequest();
//		// 记录下请求内容
//		System.out.println("============== 响应结果 START ==============");
//		System.out.println("<====== 接口地址 ====> " + request.getRequestURI());
//
//		if ("GET".equals(request.getMethod())) {
//			ObjectMapper mapper1 = new ObjectMapper();
//			String json1 = mapper1.writeValueAsString(request.getParameterMap());
//			JSONObject object1 = JSONObject.parseObject(json1);
//			String pretty1 = JSON.toJSONString(object1, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
//					SerializerFeature.WriteDateUseDateFormat);
//
//			if ("{}".equals(pretty1)) {
//				System.out.println("<====== 请求参数 ====> 无");
//			} else {
//				System.out.println("<====== 请求参数 ====> ");
//				System.out.println(pretty1);
//			}
//		} else {
//			System.out.println("<====== 请求参数 ====> 以后开发");
//		}
//
//		System.out.println("<====== 请求方式 ====> " + request.getMethod());
//		System.out.println("<====== 请求密钥 ====> " + request.getHeader("Authorization"));
//		System.out.println("<====== 请求设备 ====> " + request.getHeader("user-agent"));
//		System.out.println("<====== 响应体》 ====> ");
//		ObjectMapper mapper = new ObjectMapper();
//		String json = mapper.writeValueAsString(r);
//		JSONObject object = JSONObject.parseObject(json);
//		String pretty = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
//				SerializerFeature.WriteDateUseDateFormat);
//
//		System.out.println(pretty);
//		System.out.println("============== 响应结果 END ==============");
//	}
//
//	@SneakyThrows
//	private static String readAsChars(HttpServletRequest request) {
//
//		BufferedReader br = null;
//		StringBuilder sb = new StringBuilder("");
//		try {
//			br = request.getReader();
//			String str;
//			while ((str = br.readLine()) != null) {
//				sb.append(str);
//			}
//			br.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (null != br) {
//				try {
//					br.close();
//				} catch (IOException e) {
//					e.printStackTrace();
//				}
//			}
//		}
//		return sb.toString();
//	}
//
//}
